package com.clay.algorithm;

/**
 * @Author : clay
 * @Description:
 * @Date: Create in 20:54 2021/3/20
 * @Modified By:
 */
public class test04 {
    public static void main(String[] args) {
        int [][] martrix={{1,4,7,11,15},{2,5,8,12,19},{3,6,9,16,22},{10,13,14,17,24},{18,21,23,26,30}};
        Solution04 solution=new Solution04();
        System.out.println(solution.findNumberIn2DArray(martrix, 20));

    }

}
class Solution04 {
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
           if(matrix==null||matrix.length==0||matrix[0].length==0)
        {
            return false;
        }
        int rows=matrix.length;
        int columns=matrix[0].length;
        int row=0;
        int column=matrix[0].length-1;

        while (rows>row&&column>=0)
        {
            int num=matrix[row][column];
            if(num==target)
            {
                return true;
            }
            else if(num>target)
            {
                column--;
            }
            else
            {
                row++;
            }
        }
        return false;
    }
}
